package callable;
/*
比较runnable和callable
 */

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

//runnable创建线程
class myThread1 implements Runnable{
  @Override
  public void run() {

  }
}


//callable创建线程
class myThread2 implements Callable{
  @Override
  public Integer call() throws Exception {
    System.out.println(Thread.currentThread().getName() + " come in callable");
    return 1024;
  }
}

/*
FutureTask:先汇总再返回结果
 */
public class demo1 {

  public static void main(String[] args) throws ExecutionException, InterruptedException {

    new Thread(new myThread1(),"AA").start();

//    new Thread(new FutureTask<>(new myThread2()),"BB").start();
    myThread2 myThread2 = new myThread2();
    FutureTask futureTask = new FutureTask<>(myThread2);
    FutureTask futureTask1 = new FutureTask<>(myThread2);
    new Thread(futureTask,"lucy").start();
    new Thread(futureTask1,"mary").start();

//    while (!futureTask.isDone()){
//      System.out.println("wait...");
//    }

    System.out.println(futureTask.get());
    System.out.println(futureTask1.get());

//    System.out.println(Thread.currentThread() + " is over");


  }
}
